import React, { useEffect } from 'react'
import ReactDOM from 'react-dom/client'
import { RouterProvider } from 'react-router-dom'
import { App as AntApp, ConfigProvider } from 'antd'
import zhCN from 'antd/locale/zh_CN'
import router from '@/router/index'
import './main.css'
import { useWebsiteStore } from '@/store/useWebsiteStore'

// 添加一个包装组件来一次性加载网站配置
const AppWrapper = () => {
  const { fetchConfig } = useWebsiteStore();
  
  // 只在应用启动时加载一次配置
  useEffect(() => {
    fetchConfig();
  }, [fetchConfig]);
  
  return (
    <ConfigProvider locale={zhCN}>
      <AntApp>
        <RouterProvider router={router} />
      </AntApp>
    </ConfigProvider>
  );
};
//React.StrictMode
ReactDOM.createRoot(document.getElementById('root')!).render(
    <AppWrapper />
)
